package com.sgb.businessmodule.view.widget;

import android.content.Context;
import android.graphics.Rect;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.swgk.core.util.ScaleUtils;
import com.yalantis.ucrop.util.ScreenUtils;


public class MyItemDecoration extends RecyclerView.ItemDecoration {

    private int mSpaceSize;
    private boolean isBottom;
    private Context context;

    public MyItemDecoration(Context context) {
        mSpaceSize = 10;
        this.context = context;
    }

    public MyItemDecoration(Context context, boolean bottom) {
        mSpaceSize = 10;
        this.isBottom = bottom;
        this.context = context;
    }

    public MyItemDecoration(int spaceSize) {
        mSpaceSize = spaceSize;
    }

    @Override
    public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {

        int position = parent.getChildLayoutPosition(view);
        if (isBottom) {
            if (position == 0) {
                outRect.set(0, 0, 0, 0);
            } else {
                outRect.set(0, 0, 0, ScaleUtils.dip2px(context, mSpaceSize));
            }
        } else {
            outRect.set(0, 0, ScreenUtils.dip2px(context, mSpaceSize), ScreenUtils.dip2px(context, mSpaceSize));
        }
    }
}
